<?php
include '../controller/Conexao.php';
include '../model/Tributo.php';

class TributoDAO{
	
	public function Insere(Tributo $tributo){
		try{
			mysql_query(  "INSERT INTO tributo( nome
											  , aliquota)
									  VALUES ('".$tributo->getNome()."'
									  		 ,".$tributo->getAliquota().")" ) or die (mysql_error());
		}catch ( Exception $ex ){
			echo "Erro: ".$ex->getMessage();
		}
	}
	
	public function Remove($id){
		try{
			mysql_query("delete from tributo where idtributo=$id") or die (mysql_error());
		}catch ( Exception $ex ){
			echo "Erro: ".$ex->getMessage();
		}
	}
	
	public function Altera(Tributo $tributo){
		try{
			mysql_query(  "UPDATE tributo SET   nome 	= 	'".$tributo->getNome()."'
											  , aliquota 	= 	".$tributo->getAliquota()."
									   WHERE idtributo = ".$tributo->getIdTributo() ) or die (mysql_error());
		}catch ( Exception $ex ){
			echo "Erro: ".$ex->getMessage();
		}
							
		//header("location:../view/ListaDevices.php");
	}
	public static function GetTributos(){
	try{			
		
		}catch ( Exception $ex ){
			echo "Erro: ".$ex->getMessage();
		}
	}
	public function Lista(){
		try{			
			$rs = mysql_query( 'select * from tributo') or die(mysqli_error()) ;
			$result = array();
			while($row = mysql_fetch_object($rs)){
				array_push($result, $row);
			}	
			return $result;
		}catch ( Exception $ex ){
			echo "Erro: ".$ex->getMessage();
		}
	}
	
}	
	
?>
